//
//  ItemCellView.m
//  BalanceCar
//
//  Created by 郑信鸿 on 17/6/21.
//  Copyright © 2017年 郑信鸿. All rights reserved.
//

#import "ItemCellView.h"


@interface ItemCellView ()

@property(nonatomic, strong)NSString *imageName;

@property(nonatomic, strong)NSString *title;

@property(nonatomic, strong)UITapGestureRecognizer *tap;

@end

@implementation ItemCellView


- (UILabel *)valueLabel{
    
    if (_valueLabel == nil) {
        
        _valueLabel = [[UILabel alloc] init];
        _valueLabel.textColor = [UIColor colorFromHexCode:@"#999999"];
        _valueLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:_valueLabel];
        [_valueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.centerY.mas_offset(0);
            make.right.mas_offset(0);
            
        }];
        
    }
    
    return _valueLabel;
}


- (UIImageView *)arrowIcon{
    
    if (_arrowIcon == nil) {
        _arrowIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myinfo_list_arrow"]];
        [self addSubview:_arrowIcon];
        [_arrowIcon mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.centerY.mas_offset(0);
            make.right.mas_offset(0);
            
        }];
    }
    return _arrowIcon;
    
}

- (TipImageView *)tipImageView{
    if (_tipImageView == nil) {
        
        _tipImageView = [[TipImageView alloc] init];
        [self addSubview:_tipImageView];
        [_tipImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.centerY.mas_offset(0);
            make.right.mas_offset(0);

        }];
    }
    return _tipImageView;
}

- (UITapGestureRecognizer *)tap{
    
    if (_tap == nil) {
        
        _tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        _tap.enabled = NO;
        [self addGestureRecognizer:_tap];
        
    }
    
    return _tap;
}

- (instancetype)initWithImageName:(NSString *)imageName title:(NSString *)title{
    
    
    if (self = [super init]) {
        
        self.imageName = imageName;
        self.title = title;
        [self establishSubView];
    }
    
    return self;
}


- (void)setDelegate:(id<ItemCellViewDelegate>)delegate{
    _delegate = delegate;
    self.tap.enabled = YES;
    
}

- (void)tapAction:(UITapGestureRecognizer *)tap{
    
    if ([_delegate respondsToSelector:@selector(itemCellView:touchInWtihValue:)]) {
        
        [_delegate itemCellView:self touchInWtihValue:nil];
    }
    
}

- (void)establishSubView{
    
    
    UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:self.imageName]];
    [self addSubview:iconView];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_offset(0);
        make.left.mas_offset(0);
    }];
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.text = self.title;
    [self addSubview:titleLabel];
    titleLabel.font = [UIFont systemFontOfSize:16];
    titleLabel.textColor = [UIColor colorFromHexCode:@"#333333"];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(iconView.mas_right).offset(16);
        make.centerY.mas_offset(0);
    }];
    
    
}



@end
